package oop.ex1.orders;

import java.io.*;
import java.util.*;


/**this class contains all ordering types for this program.
 * @author miron_6 & dawn16889.
 *
 */
public class Order {

	
	/**this constant stands for "bigger than".
	 */
	private static final int BIGGER = 1;
	/**this constant stands for "smaller than".
	 */
	private static final int SMALLER = -1;
	/**this constant stands for "equal to".
	 */
	private static final int EQUAL = 0;
	

	/**class constructor.
     *
	 */
	public Order() {
	}
	
	/**this class implements Comparator for sorting file by their path name a to z.
	 * @author miron_6 & dawn16889.
	 */
	public static class absSort implements Comparator<File> {
		
		/**
		 * constructor.
		 */
		public absSort(){
		}
		
		public int compare(File one, File two) {			
			return one.getAbsolutePath().compareTo(two.getAbsolutePath());
		}
	}

	/**this class implements Comparator for sorting file by their (excluding directory) name a to z.
	 * @author miron_6 & dawn16889.
	 */
	public static class fileSort implements Comparator<File> {

		public int compare(File one, File two) {
			//if the comparing comes out equal, it compares using absSort.
			if(one.getName().compareTo(two.getName())==EQUAL)
				return one.getAbsolutePath().compareTo(two.getAbsolutePath());
			return one.getName().compareTo(two.getName());
		}
	}

	/**this class implements Comparator for sorting file by their modification date from oldest to newest.
	 * @author miron_6 & dawn16889.
	 */
	public static class modSort implements Comparator<File> {

		public int compare(File one, File two) {
			if (one.lastModified() < (two.lastModified()))
				return SMALLER;
			else if (one.lastModified() > (two.lastModified()))
				return BIGGER;
			//if the comparing comes out equal, it compares using absSort.
			return one.getAbsolutePath().compareTo(two.getAbsolutePath());
		}
	}

	/**this class implements Comparator for sorting file by their size from smallest to largest.
	 * @author miron_6 & dawn16889.
	 */
	public static class sizeSort implements Comparator<File> {

		public int compare(File one, File two) {
			if (one.length() < (two.length()))
				return SMALLER;
			else if (one.length() > (two.length()))
				return BIGGER;
			//if the comparing comes out equal, it compares using absSort.
			return one.getAbsolutePath().compareTo(two.getAbsolutePath());
		}
	}
	
	
}
